package com.hxc.orangeyule;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.util.Log;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.hxc.orangeyule.callback.DataCallBack;
import com.hxc.orangeyule.config.NetConfig;
import com.hxc.orangeyule.modle.HorScrollViewContent;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends MyFragmentActivity {

    private static final String TAG = MainActivity.class.getSimpleName();

    @ViewInject(R.id.hor_mainactivity_position)
    private HorizontalScrollView mHorizontalScrollView;
    private List<HorScrollViewContent.DataEntity> mDataEntities;
    private TextView tv;
    private LinearLayout ll;

    @ViewInject(R.id.viewpager_mainactivity)
    private ViewPager viwepager_mainactivity;
    private List<Fragment> mList;
    private FragmentPagerAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    protected void setListener() {

    }

    @Override
    protected void setData() {

        getRequset(NetConfig.HOR_SCROLLVIEW_PATH, new DataCallBack() {
            @Override
            public void onSuccessed(String result) {
                if (!TextUtils.isEmpty(result)) {
                    mDataEntities.clear();
                    mDataEntities.addAll(new Gson().fromJson(result, HorScrollViewContent.class).getData());
                    Log.d(TAG, "data.size:" + mDataEntities.size());
                    for (int i = 0; i < mDataEntities.size(); i++) {
                        String name = mDataEntities.get(i).getName();
                        if (!TextUtils.isEmpty(name)) {
                            tv = new TextView(MainActivity.this);
                            tv.setText(name);
                            tv.setTextSize(20);
                            tv.setPadding(10, 10, 10, 0);
                            ll.addView(tv);
                        }
                    }
                    mHorizontalScrollView.addView(ll);
                }
            }
        });
        mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return null;
            }

            @Override
            public int getCount() {
                return 0;
            }
        };
    }

    @Override
    protected void initView() {
        setContentView(R.layout.activity_main);
        ViewUtils.inject(this);
    }

    @Override
    protected void initData() {
        mDataEntities = new ArrayList<>();
        ll = new LinearLayout(this);
        mList = new ArrayList<>();
    }
}